package com.kata.chapter16;

/**
 * Created by Solidsnake on 2015/4/19.
 */
public class Main {

    public static void main(String[] args) {

        ITree iTree = buildData();
        printCompany(iTree);
    }

    public static ITree buildData() {
        Branch boss = new Branch("周扒皮", "陕西科创有限公司董事长", 50);
        Branch manager_1 = new Branch("王崇东", "项目组A组长", 24);
        Branch manager_2 = new Branch("安红", "项目组B组长(小蜜)", 20);

        Leaf leaf1 = new Leaf("小张", "项目组A组员--技术工程师", 30);
        Leaf leaf2 = new Leaf("小刘", "项目组A组员--技术工程师", 22);
        Leaf leaf3 = new Leaf("小狗", "项目组A组员--技术工程师", 26);

        Leaf leaf4 = new Leaf("小雅", "项目组B组员--技术工程师", 17);
        Leaf leaf5 = new Leaf("小黄", "项目组B组员--技术工程师", 16);
        Leaf leaf6 = new Leaf("小红", "项目组B组员--技术工程师", 19);

        boss.add(manager_1);
        boss.add(manager_2);
        manager_1.add(leaf1);
        manager_1.add(leaf2);
        manager_1.add(leaf3);

        manager_2.add(leaf4);
        manager_2.add(leaf5);
        manager_2.add(leaf6);

        return boss;
    }

    public static void printCompany(ITree tree) {

        if(tree instanceof Branch) {
            Branch branch = (Branch)tree;
            branch.work();
            for(ITree sub : branch.getSub()) {
                printCompany(sub);
            }
        }
        if(tree instanceof Leaf) {
            tree.work();
        }
    }
}
